<form class="layui-form" > <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->


    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">请填写描述</label>
        <div class="layui-input-block">


            <div id="editor">
                <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
            </div>
            <!--<input type="hidden" name="content" value="" id="newsContent">-->
            <!--<textarea placeholder="请输入内容" class="layui-textarea"></textarea>-->
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">资讯类型</label>
        <div class="layui-input-block">
            <select id="imageSelect" name="type" lay-filter="aihao"  lay-verify="required">
                <option value=""></option>
                <option value="爆料">爆料</option>
                <option value="公告">公告</option>
                <option value="活动">活动</option>
                <option value="攻略">攻略</option>

            </select>
        </div>
    </div>






    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>

{literal}

<script>
    $(function () {
        var E = window.wangEditor
        var editor = new E('#editor')
        // 或者 var editor = new E( document.getElementById('editor') )
        editor.customConfig.uploadImgMaxLength = 1
        editor.customConfig.uploadImgServer = '/admin/news/upload'
        editor.customConfig.uploadFileName = 'file'
        editor.create()

        layui.use(['layer', 'upload','form','table'], function(){
            var upload = layui.upload
                ,layer = layui.layer
                ,form = layui.form
                ,table = layui.table;

            //
            //监听提交



            form.on('submit(*)', function(data){
                //console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                //console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}

                let postData = data.field
                postData.content = editor.txt.html();

                console.log(postData)

                $.ajax({
                    url:'/admin/news/submitForm',
                    data:postData,
                    type:'POST',
                    success:function () {
                        layer.closeAll()


                        table.reload('newsTable')
                        layer.msg('提交成功')

                    },
                    error:function (res) {

                        layer.msg(res.responseJSON)
                    }
                })
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

        });

    })
</script>
{/literal}